home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
qbtools1.arc
/
AEBITINS.BAS
< prev
next >
Wrap
BASIC Source File
|
1987-01-11
|
3KB
|
110 lines
rem $linesize:132
rem $title:'Application Engineer Standard Routines'
rem $subtitle:'Insert a new key into the index'
' Include the COMMON values
rem $include:'AESHARED.BAS'
sub bit.ins(fl%,ky$,mrec%,success%) static
' insert a new key into the index
' use the new method, access the deletions stack.
success%=0 ' no success yet
if mrec%<1 then
success%=-1%
end if
if len(ky$)<1 then
success%=-2%
end if
' a check is needed to see if the index has grown to it's maximum
' size. a note here on how to make this index handle records greater
' than 32767. all the cvi and mki$ routines should be changed to cvs
' and mks$. also, all refernces to % (where the % is a pointer value
' in the index) should be changed to ! . the record size will increase
' as well, because the pointer fields change in length from 2 bytes to
' 4 bytes.
if xh%(fl%,2)=32767 then
success%=-3%
end if
if success%<0% then
exit sub
end if
' if the length of ky$ is less than the length of the max size for
' the key, then ky$ will be padded with blanks
if len(ky$)<xh%(fl%,1) then ky$=ky$+string$(xh%(fl%,1)-len(ky$),32)
rrec%=1
loop%=0%
while loop%=0%
prrec%=rrec% ' hold the recnum for eval
get #fl%,rrec%
if cvi(xk$(fl%,5))=0 then
goto place ' this is where the key goes
end if
if ky$<xk$(fl%,1) then
side%=2%
else
side%=3%
end if
rrec%=cvi(xk$(fl%,side%))
if rrec%=0 then
loop%=1% ' this is where the key goes
end if
wend
place:
if xh%(fl%,4%) then
gf%=4%
else
gf%=3%
end if
get #fl%,xh%(fl%,gf%)
nrec%=cvi(xk$(fl%,6%))
lset xk$(fl%,1)=ky$
if xh%(fl%,3)<>1 then
goto nfirst ' not the first record
end if
lset xk$(fl%,4)=mki$(0) ' initialize
goto other
nfirst:
lset xk$(fl%,4)=mki$(prrec%)
other:
lset xk$(fl%,3)=mki$(0)
lset xk$(fl%,2)=mki$(0)
lset xk$(fl%,5)=mki$(mrec%)
lset xk$(fl%,6)=mki$(0) ' next deleted
put #fl%,xh%(fl%,gf%)
if gf%=3% then
if xh%(fl%,3)=1 then
goto increment
end if
end if
get #fl%,prrec%
lset xk$(fl%,side%)=mki$(xh%(fl%,gf%))
put #fl%,prrec%
increment:
if gf%=4% then
xh%(fl%,4%)=nrec%
else
xh%(fl%,4%)=0%
xh%(fl%,3)=xh%(fl%,3)+1
lset xk$(fl%,1%)=string$(xh%(fl%,1%),0%)
for j%=2% to 6%
lset xk$(fl%,j%)=mki$(0%)
next j%
put #fl%,xh%(fl%,3%)
end if
xh%(fl%,2)=xh%(fl%,2)+1
success%=1
end sub